package com.hdsx.restful.glzt.structure.bzbp.rest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Service;

import com.hdsx.restful.base.PreparedDataListener;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.bzbp.bean.Bzbp;
import com.hdsx.restful.glzt.structure.bzbp.service.BzbpServer;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.util.CheckEmpty;
import com.hdsx.restful.util.Dao;
import com.hdsx.restful.util.EasyUI;


// TODO: Auto-generated Javadoc
/**
 * bzbp服务
 */
@Path("/bzbp")
@Service
public class BzbpRestServer {

	/** The bzbp server. */
	@Resource(name = "bzbpServerImpl")
	private BzbpServer server;

	/**
	 * http://192.168.0.137:8080/restful/rest/bzbp/list?lxbm=G3001&xzqhbm=610113&bzbpmc=绕城高速出长安西收费站&page=0&rows=10
	 * @param lxbm
	 * @param xzqhbm
	 * @param bzbpmc
	 * @param page
	 * @param rows
	 * @return
	 */
	@GET
	@Path("/list")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Bzbp> getList(@QueryParam("lxbm") String lxbm,@QueryParam("xzqhbm")String xzqhbm,
			@QueryParam("sxxfx") String sxxfx,@QueryParam("qdzh") String qdzh_string,
			@QueryParam("zdzh") String zdzh_string,@QueryParam("name") String name,
			@QueryParam("page") int page,@QueryParam("rows") int rows) throws Exception{
		EasyUI<Bzbp> easyUI=new EasyUI<Bzbp>(page,rows);
		Double qdzh = null;
		Double zdzh = null;
		try{
			qdzh = Double.parseDouble(qdzh_string);
			zdzh = Double.parseDouble(zdzh_string);
		}catch(Exception e){
			System.out.println("qdzh和zdzh没有输入或格式错误！");qdzh=null;zdzh=null;
		}
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		int count =server.queryCount(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
		List<Bzbp> results = server.queryList(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name,easyUI.getBegin(),easyUI.getEnd());
		easyUI.setTotal(count);
		easyUI.setRows(results);
		return easyUI;
	}
	
	@GET
	@Path("/getByBpbm")
	@Produces(MediaType.APPLICATION_JSON)
	public Bzbp getByBzbpdm(@QueryParam("bpbm") String bpbm){
		Bzbp bzbp = server.getOne(bpbm);
		return bzbp;
	}
	
	/**
	 * 根据id得到bzbp
	 * 
	 * @param id
	 *            唯一标识
	 * @return
	 */
	@GET
	@Path("/{id}")
	@Produces(MediaType.APPLICATION_JSON)
	public Bzbp getById(@PathParam("id") String id) {
		Bzbp bzbp = server.getById(id);
		return bzbp;
	}

	
	@GET
	@Path("/info")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Dao> getShapeById(@QueryParam("id") String id) {
		return server.getShapeById(id);
	}
	@GET
	@Path("/tjjg")
	@Produces(MediaType.APPLICATION_JSON)
	public StatisticalResult getStatisticalResult(@QueryParam("szlx") String szlx,@QueryParam("xzqhbm") String xzqhbm,@QueryParam("type") String type){
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lxbm", szlx);
		map.put("xzqhbm", xzqhbm);
		map.put("type", type);
		StatisticalResult tjjg = server.countByParameter(map);
		return tjjg;
	}
	@GET
   	@Path("/bzbpNode")
   	@Produces(MediaType.APPLICATION_JSON)
   	public List<Znode> tree(){
   		return PreparedDataListener.getData("bzbp");
//		return server.bzbpNode();
   	}
	
	/**
	 * http://192.168.0.137:8080/restful/rest/bzbp/list?lxbm=G3001&xzqhbm=610113&bzbpmc=绕城高速出长安西收费站&page=0&rows=10
	 * @return
	 */
	@GET
	@Path("/all")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Bzbp> all(@QueryParam("lxbm") String lxbm,@QueryParam("xzqhbm")String xzqhbm,
			@QueryParam("sxxfx") String sxxfx,@QueryParam("qdzh") String qdzh_string,
			@QueryParam("zdzh") String zdzh_string,@QueryParam("name") String name){
		Double qdzh = null;
		Double zdzh = null;
		try{
			qdzh = Double.parseDouble(qdzh_string);
			zdzh = Double.parseDouble(zdzh_string);
		}catch(Exception e){
			System.out.println("qdzh和zdzh没有输入或格式错误！");qdzh=null;zdzh=null;
		}
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		List<Bzbp> list = server.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
		return list;
	}
	
	
	/**
	 * http://192.168.0.137:8080/restful/rest/bzbp/list?lxbm=G3001&xzqhbm=610113&bzbpmc=绕城高速出长安西收费站&page=0&rows=10
	 */
	@GET
	@Path("/one")
	@Produces(MediaType.APPLICATION_JSON)
	public Bzbp one(@QueryParam("id")String id){
		Bzbp one = server.queryById(id);
		return one;
	}
	
	@GET
	@Path("/detail")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Bzbp> detail(@QueryParam("szlx") String szlx,@QueryParam("xzqhbm") String xzqhbm,
			@QueryParam("lxfl") String lxfl,@QueryParam("page") int page,@QueryParam("rows") int rows){
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		EasyUI<Bzbp> easyUI = new EasyUI<Bzbp>(page, rows);
		Map<String, Object> map = easyUI.getParameter();
		map.put("lxbm", szlx);
		map.put("xzqhbm", xzqhbm);
		try{
			map.put("lxfl", Integer.parseInt(lxfl));
		}catch (Exception e){
			System.out.println("不是类型分类！");
		}
		List<Bzbp> detail = server.detail(map);
		int total = server.countDetail(map);
		easyUI.setRows(detail);
		easyUI.setTotal(total);
		return easyUI;
	}
	
	@GET
	@Path("/auto")
	@Produces(MediaType.APPLICATION_JSON)
	public List<String> pienext(@QueryParam("name")String name){
		return server.selectName(name);
	}
}
